package com.neu.service;

import com.neu.dao.StaffDao;
//import com.neu.pojo.Role;
import com.neu.pojo.Staff;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
//import org.springframework.security.core.authority.*
import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional
public class StaffServiceImpl implements StaffService{

    @Resource
    private StaffDao staffDao;

    //创建角色列表集合
  /*  List<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
    public UserDetails loadUserByUsername(String staffName) throws UsernameNotFoundException {
        //调用根据用户姓名查询用户信息的方法
        Staff staff = staffMapper.findStaffByStaffName(staffName);

        for (Role role : staff.getRoleList()) {
            //将角色编码添加到角色列表集合中
            authorities.add(new SimpleGrantedAuthority(role.getRoleCode()));
        }
        //创建Staff对象
        User user = new User(staff.getStaffName(),staff.getPassword(),true,true,true,true, (Collection<? extends GrantedAuthority>) authorities);
        return user;
    }
    */
    public Staff login(Staff staff){
        Staff s = staffDao.login(staff);
        return s;
    }

    public int insertStaff(Staff staff) {
        return staffDao.insertStaff(staff);
    }

    public int updateStaff(Staff staff) {
        return staffDao.updateStaff(staff);
    }

    public int deleteStaffById(int id) {
        //删除用户角色关系表的数据
       // staffMapper.deleteUserRoleByUserId(id);
        //删除用户数据
        return staffDao.deleteStaffById(id);
    }

//    public int resetPwd(Integer id, Integer userId) {
//        //创建用户对象
//        Staff staff = new Staff();
//        staff.setStaffId(id);//用户ID
//        //staff.setModifyBy(userId);//修改人
//        staff.setPassword("123456");
//        return staffDao.updateStaff(staff);
//    }


    public Staff findStaffByStaffName(String staffName,String password) {
        return staffDao.findStaffByStaffName(staffName, password);
    }

    public Staff findStaffByStaffId(int staffId) {
        return staffDao.findStaffByStaffId(staffId);
    }

    public List<Staff> findStaffList(){
        return staffDao.findStaffList();
    }

    public int getStaffCount(){
        return staffDao.getStaffCount();
    }
    public List<Staff> getStaffByPage(int page,int limit){
        return staffDao.getStaffByPage((page-1)*limit,limit);
    }
}
